package com.youlai.boot.system.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.boot.system.mapper.LpsOrderXianMapper;
import com.youlai.boot.system.service.LpsOrderXianService;
import com.youlai.boot.system.model.entity.LpsOrderXian;
import com.youlai.boot.system.model.form.LpsOrderXianForm;
import com.youlai.boot.system.model.query.LpsOrderXianQuery;
import com.youlai.boot.system.model.vo.LpsOrderXianVO;
import com.youlai.boot.system.converter.LpsOrderXianConverter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;

/**
 * 新产品 线服务实现类
 *
 * @author lwb
 * @since 2025-07-14 16:24
 */
@Service
@RequiredArgsConstructor
public class LpsOrderXianServiceImpl extends ServiceImpl<LpsOrderXianMapper, LpsOrderXian> implements LpsOrderXianService {

    private final LpsOrderXianConverter lpsOrderXianConverter;

    /**
    * 获取新产品 线分页列表
    *
    * @param queryParams 查询参数
    * @return {@link IPage<LpsOrderXianVO>} 新产品 线分页列表
    */
    @Override
    public IPage<LpsOrderXianVO> getLpsOrderXianPage(LpsOrderXianQuery queryParams) {
        Page<LpsOrderXianVO> pageVO = this.baseMapper.getLpsOrderXianPage(
                new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
                queryParams
        );
        return pageVO;
    }
    
    /**
     * 获取新产品 线表单数据
     *
     * @param id 新产品 线ID
     * @return
     */
    @Override
    public LpsOrderXianForm getLpsOrderXianFormData(Long id) {
        LpsOrderXian entity = this.getById(id);
        return lpsOrderXianConverter.toForm(entity);
    }
    
    /**
     * 新增新产品 线
     *
     * @param formData 新产品 线表单对象
     * @return
     */
    @Override
    public boolean saveLpsOrderXian(LpsOrderXianForm formData) {
        LpsOrderXian entity = lpsOrderXianConverter.toEntity(formData);
        return this.save(entity);
    }
    
    /**
     * 更新新产品 线
     *
     * @param id   新产品 线ID
     * @param formData 新产品 线表单对象
     * @return
     */
    @Override
    public boolean updateLpsOrderXian(Long id,LpsOrderXianForm formData) {
        LpsOrderXian entity = lpsOrderXianConverter.toEntity(formData);
        return this.updateById(entity);
    }
    
    /**
     * 删除新产品 线
     *
     * @param ids 新产品 线ID，多个以英文逗号(,)分割
     * @return
     */
    @Override
    public boolean deleteLpsOrderXians(String ids) {
        Assert.isTrue(StrUtil.isNotBlank(ids), "删除的新产品 线数据为空");
        // 逻辑删除
        List<Long> idList = Arrays.stream(ids.split(","))
                .map(Long::parseLong)
                .toList();
        return this.removeByIds(idList);
    }

}
